// serverMiddleware.js
export default (request, response, next) => {
    const path = request.url || "";

    if (request.method == "POST" && path.indexOf("/app/oceanpay") == 0) {
        const body = [];

        request.on("data", (chunk) => {
            body.push(chunk);
        });
        request.on("end", () => {
            const contenttype = request.headers["content-type"] || "";
            request.body = Buffer.concat(body).toString();

            // if (contenttype.search("multipart/form-data;") >= 0) {
            //     // form-data
            //     // } else if (contenttype.search("text/plain") >= 0) {
            //     // request.body = new URLSearchParams(body);
            //     // request.body = body;
            //     request.body = 111;
            // } else {
            //     request.body = body;
            // }
            next();
        });

        request.on("error", () => {
            next();
        });
    } else {
        next();
    }
};
